//
//  TFStatus.swift
//  weiboSina
//
//  Created by admin on 16/1/2.
//  Copyright © 2016年 admin. All rights reserved.
//

import UIKit

class TFStatus: NSObject {
    
    //微博内容
    var text: String?
    /**
     微博的创建时间
     */
    var created_at: String?
    /**
     微博的来源
     */
    var source: String?
    /**
     当前微博的作者信息
     */
    var user: TFUser?
    /**
     转发微博的字段
     */
     
    var retweeted_status: TFStatus?
    /**
     转发数
     */
    var reposts_count: Int = 0
    /**
     评论数
     */
    var comments_count: Int = 0
    /**
     点赞数
     */
    var attitudes_count: Int = 0
    
    /**
     配图视图需要的数据
     */
    var pic_urls: [TFStatusPictureInfo]?
    
    init(dict:[String: AnyObject]) {
        super.init()

        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user"{
        
            if let dict = value as? [String: AnyObject]{
            
            //字典转模型
                user = TFUser(dict: dict)
            }
        
        }else if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject]{
                /**
                字典转模型
                */
                retweeted_status = TFStatus(dict: dict)
            
            }
       }else if key == "pic_urls"{
            
            if let dicts = value as? [[String: AnyObject]]{
                //初始化一个配图数据的数组
                pic_urls = [TFStatusPictureInfo]()
                //遍历字典转模型
                for dict in dicts{
                    let pictureInfo = TFStatusPictureInfo(dict: dict)
                    pic_urls?.append(pictureInfo)
                    
                }
            }
        
        }else{
        //一定要调用super,因为super方法才是真正的赋值
            
            super.setValue(value, forKey: key)
        
        }
    }
    
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        //防止抛出错误
    }
    
    
//   override var description: String {
//    
//    let keys = ["pic_urls"]
//    return dictionaryWithValuesForKeys(keys).description
//    
//    }
//    
    
    
    
}
